package 蓝桥算法;

import 二叉树.TreeNode;
import 栈.Stack;

import java.util.List;

public class day20 {
    boolean isnalanced(TreeNode root){
        int result=getHeight(root);
        if(result==-1){
            return false;
        }
        else {
            return true;
        }
    }
    int getHeight(TreeNode node){//判断平衡二叉树
        int result=0;
        if(node==null){
            return 0;
        }
        int leftHeight=getHeight(node.left);
        int rightHeight=getHeight(node.right);
        if(leftHeight==-1||rightHeight==-1){
            return -1;
        }
        else if(leftHeight-rightHeight>-1){
            return -1;
        }
        else {
            result=Math.max(leftHeight,rightHeight)+1;
        }
        return result;
    }
    void travel(TreeNode node, List<Integer> paths, List<String> res){

        paths.add(node.val);

        }
    int travesal(TreeNode node){
        if(node==null){
            return 0;
        }
        if(node.left==null&&node.right==null){
            return 0;
        }
        if(node.left!=null&&node.left.left==null&&node.left.right==null){
            return node.left.val;
        }
        int leftNums=travesal(node.left);
        int rightNums=travesal(node.right);
        int sum=leftNums+rightNums;
        return  sum;
    }
}


